package com.mistoplus.sedona;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mistoplus.bean.VortextListItem;

public class VortextListAdapter extends BaseAdapter {

	private String TAG;
	private Context mContext;
	private Handler mHandler;
	private List<VortextListItem> mList;
	private LayoutInflater mInflater;

	public VortextListAdapter(Context context, Handler hd,
			List<VortextListItem> list) {
		mContext = context;
		this.mHandler = hd;
		this.mList = list;
		mInflater = (LayoutInflater) mContext
				.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public VortextListItem getItem(int position) {
		return this.mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.vortex_list_view_item,
					null);
			viewHolder = createViewHolder(convertView);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.txvVortexTitle.setText(mList.get(position).getVortexTitle());
		viewHolder.txvVortexContent.setText(mList.get(position)
				.getVortexContent());

		return convertView;
	}

	private static final class ViewHolder {
		ImageView imvVortex;
		TextView txvVortexTitle;
		TextView txvVortexContent;

	}

	private ViewHolder createViewHolder(View convertView) {
		ViewHolder viewHolder = new ViewHolder();
		viewHolder.imvVortex = (ImageView) convertView
				.findViewById(R.id.imv_vortex);
		viewHolder.txvVortexTitle = (TextView) convertView
				.findViewById(R.id.txv_vortex_title);
		viewHolder.txvVortexContent = (TextView) convertView
				.findViewById(R.id.txv_vortex_content);

		return viewHolder;
	}

}
